<?php
include_once('ClsSebent/config.php');
$quan=$qty;
$incr=0;
//CALCULATE THE PRICE INCREASE ACCORDING TO ADDONS
if($addon!=0)
{
	$mq="select * from product_addon where addon_id=".$addon;
	$mr=mysql_query($mq);
	$mres=mysql_fetch_array($mr);
	
	if($quan>0)
	{
	if($quan>=1 && $quan<=$mres['slot1'])
	$incr=$mres['pr_inc1'];
	if($quan>=($mres['slot1']+1) && $quan<=$mres['slot2'])
	$incr=$mres['pr_inc2'];
	if($quan>=($mres['slot2']+1) && $quan<=$mres['slot3'])
	$incr=$mres['pr_inc3'];
	if($quan>=($mres['slot3']+1) && $quan<=$mres['slot4'])
	$incr=$mres['pr_inc4'];
	if($quan>=($mres['slot4']+1) && $quan<=$mres['slot5'])
	$incr=$mres['pr_inc5'];
	if($quan>=($mres['slot5']+1) && $quan<=$mres['slot6'])
	$incr=$mres['pr_inc6'];
	}
}
//****************************************************************** 
//echo $quan;
$calqry="select * from product_master where id=".$pid;
//echo $calqry;
$calr=mysql_query($calqry);
$calrow=mysql_fetch_array($calr);
//$price=$calrow["price"];
$lot=$calrow["lot_size"];
$discnt=$calrow["lot_discount"];
$max_discount=$calrow["max_discount"];
$lots=$qty/$lot;
$Tdiscnt=abs($discnt*(integer)$lots);
if($Tdiscnt>$max_discount) $Tdiscnt=$max_discount;
$qr="select * from site_product where product_id=".$pid." and site_id=".$_SESSION['SITE_ID'];
//echo $qr;
$rqr=mysql_query($qr);
$row=mysql_fetch_array($rqr);
$f_price=$row["final_price"];
//echo $f_price;
$Tprice=$f_price*$quan;
$Gprice=$Tprice-$Tdiscnt+$incr;
//echo "price:$price Lot:$lots Disc:$discnt Tdis:$Tdiscnt Tpric:$Tprice Gpric:$Gprice";
?>
<script type="text/javascript">
window.opener.document.formx.Tprice.value='<?php echo $Tprice;?>';
window.opener.document.formx.discount.value='<?php echo $Tdiscnt;?>';
window.opener.document.formx.addon_inc.value='<?php echo $incr;?>';
window.opener.document.formx.Fprice.value='<?php echo $Gprice;?>';
window.close('cart_calculate.php');
</script> 